﻿using Lamex.Base;
using Lamex.mIE.DalServer;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lamex.mIE.Common
{
    public class GetLock
    {
        //解锁当前用户锁定的图纸
        public static void UnLock()
        {
            string sqlUnLock = @"update IE_Part_TaskList set CURRENT_USERS='' where CURRENT_USERS='" + Lamex.Common.Loginer.CurrentUser.AccountName + "'";
            BaseFactory<IE_Part_TaskList>.Instance.ExecuteNonQuery(sqlUnLock);
        }
        //锁定当前用户操作的图纸
        public static void LockUser(string values)
        {
            string sqlLock = @"update IE_Part_TaskList set CURRENT_USERS='" + Lamex.Common.Loginer.CurrentUser.AccountName + "' where DWG_NO='" + values + "' OR PART_NO='" + values + "'";
            BaseFactory<IE_Part_TaskList>.Instance.ExecuteNonQuery(sqlLock);
        }
        //控制是否被锁定
        public static string GetUser(string values)
        {
            string UserName = "";
            string sqlControl = @"select CURRENT_USERS from IE_Part_TaskList where  DWG_NO='" + values + "' OR PART_NO='" + values + "'";
            DataTable dt1 = BaseFactory<IE_Part_TaskList>.Instance.GetDataTableBySql(sqlControl);
            if (dt1.Rows.Count > 0)
            {
                string name = dt1.Rows[0]["CURRENT_USERS"].ToString();
                if (name != Lamex.Common.Loginer.CurrentUser.AccountName && !string.IsNullOrEmpty(name))
                {
                    UserName = name;
                }
            }
            return UserName;
        }
    }
}
